package com.example.demo.spring;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * @author Rocket
 * @version 10.0.1
 * @date 2021-08-22 1:22 PM
 */
@Configuration
public class SpringTest implements InitializingBean, DisposableBean {


    @Bean(name = "domainUser")
    public User getDomainUser() {

        return UserFactory.getUsers(DomainUser.class);
    }

    @Bean(name = "adminUser")
    public User getAdminUser() {
        return UserFactory.getUsers(AdminUser.class);
    }

    @PreDestroy
    public void PreDestroy() {
        System.out.println("PreDestroy is invoked");
    }

    @PostConstruct
    public void postConstruct() {
        System.out.println("postConstruct is invoked");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("bean init...");
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("bean destroyed...");
    }
}
